<!-- 顶部蓝色 -->
<template>
	<view class="contaier">
		<view class="top-bg">
			<view class="text-white text-bold text-xxxl">药店销售系统</view>
			<view class="margin-top-xs text-white">欢迎使用，请先登录</view>
		</view>
		
		<view class="input-box padding-lr">
			<form>
				<view class="cu-form-group margin-top">
					<view class="title">账号</view>
					<input placeholder="请输入账号" v-model="userName" />
				</view>
				<view class="cu-form-group">
					<view class="title">密码</view>
					<input placeholder="请输入密码" v-model="password" type='password'/>
				</view>
			</form>
		</view>
		
		<view class="padding margin-top-xs">
			<button class="cu-btn block round bg-login-zl margin-tb-sm lg" @click="login">立即登录</button>
			<!-- <view class="text-gray flex justify-between padding-lr-sm">
				<text>注册账号</text>
				<text>忘记密码</text>
			</view> -->
		</view>
		<quick-message ref="message"></quick-message>
		
	</view>
</template>
<script>
	import mRequest from "@/api/index";
	import hccmStore from '@/common/hccm-store'
	export default {
		data() {
			return {
				userName: '',
				password: '',
				// userName: 'wangzhe',
				// password: '666666',
			};
		},
		onLoad() {
			if(hccmStore.getUser()){
				uni.reLaunch({
					url: '/pages/home-main/home-main'
				})
			}
		},
		methods: {
			login(){
				let params = {
					userName: this.userName,
					password: this.password,
				}
				mRequest.byPassword(params).then(res=>{
					console.log(res,res)
					if(res.code === 0){
						hccmStore.setPhoneToken(res.token)
						hccmStore.setUser(res.userInfo)
						hccmStore.setRole(res.roles)
						this.$refs.message.show({
							type:'success', //String 默认default
							msg:'登录成功', //String 显示内容 *
							direction:'top', //String 默认顶部显示
							icon:true, //Boolean|String 显示icon(false/true/string 默认显示icon)
							mask:true, //Boolean 遮罩（默认false没有遮罩）
							time:1000, //Number|Boolean 默认3000/false为不自动关闭
							customStyle:{ //自定义样式
								// color:'#FFFFFF', //字体图标色
								// backgroundColor:'rgba(0,0,0,.5)', //背景色
								fontSize: 12,
							}, 
							iconSize: 16, //Number 自定义icon大小(单位px 默认16 设置后会覆盖自定义样式里的设置优先级最高)
							iconColor: '', //String icon颜色(默认主题颜色 设置后会覆盖自定义样式里的设置优先级最高)
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/home-main/home-main'
							})
						}, 1000)
					}
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.contaier{
		height: 100vh;
		background-color: #ffffff;
	}
	.top-bg{
		width: 750rpx;
    background: url(~@/static/image/head-bg.png);
		height: 480rpx;
		background-size: 100%;
		background-repeat: no-repeat;
		text-align: center;
		padding-top: 170rpx;
	}
	.bg-login-zl {
		background-image: linear-gradient(45deg, #727CFB, #46D0ED);
		color: #ffffff;
	}
</style>
